package com.em.tuppence.backend.daemon;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import com.sun.jersey.spi.container.servlet.ServletContainer;




public class Controller {

	public static void main(String[] args) {
		
		//create and start jetty server
		Server server = new Server(2552);
		
		//add server stuff
		ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
		context.setContextPath("/");
		
		//set jersey servlet
		ServletHolder jerseyHolder = new ServletHolder();
		jerseyHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.em.tuppence.backend.packages");
		jerseyHolder.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
		jerseyHolder.setName("jersey-container");
		jerseyHolder.setEnabled(true);
		jerseyHolder.setInitOrder(0);
		jerseyHolder.setClassName(ServletContainer.class.getName());
	
		//load servlet
		context.addServlet(jerseyHolder, "/*");		
		
		//set context into global server handler
		server.setHandler(context);
		
		//start the server
		try {
			server.start();

			//join and wait
			try {
				server.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}		
		
		//leave
	}
	
}
